﻿using System;

namespace QunYing.Common
{
    public class ImageHelper
    {
        ///<summary>
        ///将Image对象转化成二进制流
        ///</summary>
        ///<returns></returns>
        public static byte[] ImageToByteArray(System.Drawing.Image image)
        {
            //实例化流
            System.IO.MemoryStream imageStream = new System.IO.MemoryStream();
            //将图片的实例保存到流中
            image.Save(imageStream, System.Drawing.Imaging.ImageFormat.Jpeg);
            //保存流的二进制数组
            byte[] imageContent = new Byte[imageStream.Length];
            imageStream.Position = 0;
            //将流泻如数组中
            imageStream.Read(imageContent, 0, (int)imageStream.Length);
            return imageStream.ToArray();
        }
    }
}
